// zh_gjw/pages/market/market.js
var util = require('../../utils/util.js');
// var timePicker = require('../../utils/timePicker.js');
var ndates = new Date();
var ndate = ndates.getFullYear() + '-' + (ndates.getMonth() + 1) + '-' + ndates.getDate()
var ntime = ndates.getHours() + ':' + ndates.getMinutes() + ':' + ndates.getSeconds()
var starttime = ndates.getFullYear() + '-' + (ndates.getMonth() + 1) + '-' + (ndates.getDate() + 1)
Page({

  /**
   * 页面的初始数据
   */
	data: {
		show0: false,
		showp0: true,
		show1: false,
		showp1: true,
		show2: false,
		showp2: true,
		show:0,
		upload_img: [],
		uploadimg: [],
		shotcate0: [],
		shotcate1: [],
		shotcate2: [],
		shotcateindex0: 0,
		shotcateindex1: 0,
		shotcateindex2: 0,
    upshot: [
      { name: '1', value: '推荐' },
      { name: '0', value: '不推荐', checked: 'true' },
		],
		times: ntime,
		time: ntime,
		ntime: ntime,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		var that = this
		var starttime = util.formatTime(new Date).substring(0, 10).replace(/\//g, "-");

		// var startsec = timePicker.timePicker(util.formatTime(new Date()));
		
		that.setData({
			admin: options.admin,
			dates: starttime,
			date: starttime,
			starttime: starttime,
		})
		
		that.setData({
			admin: options.admin
		})
		getApp().util.request({
			'url': 'entry/wxapp/Marketmoney',
			'cachetime': '0',
			success: function (res) {
				
				that.setData({
					publishfee: res.data.res.publishfee,
					upfee: res.data.res.upfee,
					topfee: res.data.res.topfee,
          // marketbzj: res.data.res.bzj,
				})
			}
		})
    getApp().util.request({
			'url': 'entry/wxapp/catestop',
      'cachetime': '0',
      success: function (res) {
        
				var result = []
				var resultid = []
        for (var i = 0; i < res.data.res.length; i++) {
					result.push(res.data.res[i].cate)
					resultid.push(res.data.res[i].id)
        }
				
				
        that.setData({
					shotcate0: result,
					shotcateid0: resultid,
        })
      }
    });
		getApp().util.request({
			'url': 'entry/wxapp/Shset',
			'cachetime': '0',
			success: function (res) {
				
				that.setData({
					marketshset: res.data.res.marketshset
				})
			}
		});
		getApp().util.request({
			url: 'entry/wxapp/Recostis',
			data: { openid: wx.getStorageSync('openid') },
			success: function (res) {
				if (res.data.code == 200) {
					that.setData({
						total: res.data.total
					})
				}
			}
		})
		getApp().util.request({
			url: 'entry/wxapp/Repucostmarketf',
			data: { openid: wx.getStorageSync('openid') },
			success: function (res) {
				if (res.data.code == 200) {
					that.setData({
						rest: res.data.rest,
						restup: res.data.restup
					})
				}
			}
		})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  radioChange: function (e) {
		this.setData({
			upstate: e.detail.value
		})
  },
  bindPickerChange0: function (e) {
    
		var that=this
    this.setData({
			shotcateindex0: e.detail.value,
			show0:true,
			showp0:false
			// noneo: 0
    })
		getApp().util.request({
			'url': 'entry/wxapp/Catessub',
			'cachetime': '0',
			data:{pid:that.data.shotcateid0[e.detail.value]},
			success: function (res) {
				
				var result = []
				var resultid = []
				for (var i = 0; i < res.data.res.length; i++) {
					result.push(res.data.res[i].cate)
					resultid.push(res.data.res[i].id)
				}
				
				
				that.setData({
					shotcate1: result,
					shotcateid1: resultid,
					show1: true,
					showp1: false
				})
				getApp().util.request({
					'url': 'entry/wxapp/Catessub',
					'cachetime': '0',
					data: { pid: resultid[0] },
					success: function (ress) {
						if (ress.data.code==200){
							var results = []
							var resultids = []
							for (var j = 0; j < ress.data.res.length; j++) {
								results.push(ress.data.res[j].cate)
								resultids.push(ress.data.res[j].id)
							}
							that.setData({
								shotcate2: results,
								shotcateid2: resultids,
								show2: true,
								showp2: false
							})
						}else{
							that.setData({
								shotcate2: [],
								shotcateid2: [],
								show2: true,
								showp2: false
							})
						}
					}
				});
			}
		});
  },
	bindPickerChange1: function (e) {
		var that = this
		this.setData({
			shotcateindex1: e.detail.value,
			show1: true,
			showp1: false
			// nonet: 0
		})
		getApp().util.request({
			'url': 'entry/wxapp/Catessub',
			'cachetime': '0',
			data: { pid: that.data.shotcateid1[e.detail.value] },
			success: function (res) {
				
				var result = []
				var resultid = []
				for (var i = 0; i < res.data.res.length; i++) {
					result.push(res.data.res[i].cate)
					resultid.push(res.data.res[i].id)
				}
				
				
				that.setData({
					shotcate2: result,
					shotcateid2: resultid,
				})
			}
		});
	},
	bindPickerChange2: function (e) {
		
		this.setData({
			shotcateindex2: e.detail.value,
			show2: true,
			showp2: false
		})
	},
	bindDateChanges: function (e) {
		var that = this
		
		this.setData({
			dates: e.detail.value
		})
		if (e.detail.value == that.data.starttime) {
			that.setData({
				times: that.data.ntime
			})
		}
	},
	bindTimeChanges: function (e) {
		
		this.setData({
			times: e.detail.value
		})
	},
	bindDateChange: function (e) {
		
		this.setData({
			date: e.detail.value
		})
	},
	bindTimeChange: function (e) {
		
		this.setData({
			time: e.detail.value
		})
	},
	upvideo: function () {
		var that = this

		wx.chooseVideo({
			sourceType: ['album', 'camera'],
			maxDuration: 15,
			camera: ['front', 'back'],
			success: function (res) {
				
				if (res.duration < 15) {
					that.setData({
						show: 1,
						videosrc: res.tempFilePath,
						videotime: res.duration,
					})
					
				} else {
					wx.showToast({
						title: '视频超过15秒了',
						icon: 'none',
						duration: 3000
					})
				}
			},
			fail: function (res) {
				
			},
			complete: function (res) {
				
			}
		})
	},
	chooseImage3: function () {
		var that = this
		var upload_img = this.data.upload_img
		
		var img_length = 9 - upload_img.length
		if (img_length > 0 && img_length <= 9) {
			// 选择图片
			wx.chooseImage({
				count: img_length,
				sizeType: ['compressed'],
				sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				success: function (res) {
					wx.showToast({
						icon: "loading",
						title: "正在上传",
						duration: 3000
					})
					// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
					var tempFilePaths = res.tempFilePaths;
					upload_img = upload_img.concat(tempFilePaths)
					
					that.setData({
						upload_img: upload_img,
					});
				}
			})
		}
	},
	already: function (data) {
		var that = this,
			i = data.i ? data.i : 0
		wx.uploadFile({
			url: data.url,
			filePath: data.path[i],
			name: 'upload_file',
			formData: null,
			success: (resp) => {
				var imgtemp = resp.data.replace('["', "")
				imgtemp = imgtemp.replace('"]', "")
				that.data.uploadimg.push(imgtemp)
			},
			complete: (res) => {
				i++;
				if (i == data.path.length) {
					that.submit()
				} else {
					data.i = i;
					that.already(data);
				}
			}
		});
	},
	delete: function (e) {
		
		var that = this
		var index = e.currentTarget.dataset.index
		
		that.data.upload_img.splice(index, 1);
		
		that.setData({
			upload_img: that.data.upload_img
		});
		that.uniques(that.data.uploadimg)
		
		that.data.uploadimg.splice(index, 1);
		
	},
	uniques: function (arr) {
		var len = arr.length;
		var result = []
		for (var i = 0; i < len; i++) {
			var flag = true;
			for (var j = i; j < arr.length - 1; j++) {
				if (arr[i] == arr[j + 1]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				result.push(arr[i])
			}
		}
		this.data.uploadimg = result
	},
	formSubmit: function (e) {
		var that = this
		// return
		var formid = e.detail.formId;
		
		var fromtime = that.data.dates + ' ' + that.data.times;
		var totime = that.data.date + ' ' + that.data.time;
		// var bzj = e.detail.value.lmoney * 0.1
		// if (that.data.date <= that.data.dates && that.data.time.slice(0, 5) <= that.data.times.slice(0, 5)) {
		// 	wx.showToast({
		// 		title: '起始时间与截止时间不正常哟',
		// 		icon: 'none',
		// 		duration: 3000
		// 	})
		// } else 
		if (e.detail.value.title == '') {
			wx.showToast({
				title: '标题不能为空',
				icon: 'none',
				duration: 3000
			})
		}
		//  else if (e.detail.value.fmoney == '') {
		// 	wx.showToast({
		// 		title: '起拍价不能为空',
		// 		icon: 'none',
		// 		duration: 3000
		// 	})
		// }
		 else if (e.detail.value.lmoney < 1) {
			wx.showToast({
				title: '参考价不能为小于1',
				icon: 'none',
				duration: 3000
			})
		} else if (e.detail.value.exfee == '') {
			wx.showToast({
				title: '快递/物流费不能为空',
				icon: 'none',
				duration: 3000
			})
		} else if (that.data.upload_img.length < 1 && that.data.videosrc == undefined) {
			wx.showToast({
				title: '请至少上传一张图片或视频',
				icon: 'none',
				duration: 3000
			})
		} else if (that.data.shotcateid2== undefined) {
			wx.showToast({
				title: '好像还没有选择三级分类',
				icon: 'none',
				duration: 3000
			})
		} else {
			that.setData({
				tmdformid: formid,
				tmdtitle: e.detail.value.title,
				tmdfmoney: e.detail.value.fmoney,
				tmdlmoney: e.detail.value.lmoney,
				// tmdbzj: that.data.marketbzj,
				// tmduserbzj: e.detail.value.userbzj,
				tmdexfee: e.detail.value.exfee,
				tmddetail: e.detail.value.textarea,
				tmdco_id: that.data.shotcateid0[that.data.shotcateindex0],
				tmdct_id: that.data.shotcateid1[that.data.shotcateindex1],
				tmdcth_id: that.data.shotcateid2[that.data.shotcateindex2],
				tmdtotime: totime,
				tmdfromtime: fromtime,
				tmdadmin: that.data.admin,
			})
			wx.showLoading({
				title: '正在上传',
			})
			if (that.data.videosrc != undefined && that.data.upload_img.length < 1) {
				wx.uploadFile({
					url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploadvideo&m=zh_gjw',
					filePath: that.data.videosrc,
					name: 'upload_file',
					formData: null,
					success: function (res) {
						
						
						var videoimgtemp = res.data.replace('["', "")
						videoimgtemp = videoimgtemp.replace('"]', "")
						that.setData({
							videoimgtemp: videoimgtemp
						})
						that.submit()
					}
				})
			}
			if (that.data.upload_img.length >= 1 && that.data.videosrc == undefined) {
				that.already({
					url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploads&m=zh_gjw',
					path: that.data.upload_img
				})
			}
			if (that.data.upload_img.length >= 1 && that.data.videosrc != undefined) {
				wx.uploadFile({
					url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploadvideo&m=zh_gjw',
					filePath: that.data.videosrc,
					name: 'upload_file',
					formData: null,
					success: function (res) {
						
						
						var videoimgtemp = res.data.replace('["', "")
						videoimgtemp = videoimgtemp.replace('"]', "")
						that.setData({
							videoimgtemp: videoimgtemp
						})
						that.already({
							url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploads&m=zh_gjw',
							path: that.data.upload_img
						});
					}
				})
			}
			
		}
	},
	submit: function () {//发布方式（商家用户、信誉、发布费、推荐）：1、1000；2、1001；3、1010；4、1011；5、1(00)00；6、1(00)01；7、1(00)10；8、1(00)11；9、1(01)00；10、1(01)01；11、1(01)10；12、1(01)11；13、1(10)00；14、1(10)01；15、1(10)10；16、1(10)11；17、1(11)00；18、1(11)01；19、1(11)10；20、1(11)11；
		var that = this
		that.uniques(that.data.uploadimg)
		var imgstr = that.data.uploadimg.toString()
		getApp().util.request({
			'url': 'entry/wxapp/Marketpublish',
			'cachetime': '0',
			data: { 
				formid: that.data.tmdformid, 
				title: that.data.tmdtitle, 
				fmoney: that.data.tmdfmoney, 
				lmoney: that.data.tmdlmoney, 
				// bzj: that.data.tmdbzj,
				// userbzj: that.data.tmduserbzj, 
				exfee: that.data.tmdexfee, 
				detail: that.data.tmddetail, 
				co_id: that.data.tmdco_id, 
				ct_id: that.data.tmdct_id, 
				cth_id: that.data.tmdcth_id, 
				totime: that.data.tmdtotime, 
				fromtime: that.data.tmdfromtime,
				admin: that.data.tmdadmin, 
				img: imgstr, 
				videoimgtemp: that.data.videoimgtemp 
			},
			success: function (res) {
				if (res.data.code == 200) {
					if (that.data.total > 0){
						if (that.data.upstate != 1 && that.data.rest == 0 && that.data.restup == 0) {//5、7
							if (that.data.publishfee > 0) {//1(00)10
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 7
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1(00)00
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 5
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						} else if(that.data.upstate == 1 && that.data.rest == 0 && that.data.restup == 0) {//6、8
							if (that.data.publishfee > 0) {//1(00)11
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 8
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1(00)01
								if(that.data.upfee>0){
									getApp().util.request({
										'url': 'entry/wxapp/Marketpay',
										'cachetime': '0',
										data: {
											openid: wx.getStorageSync('openid'),
											publishfee: that.data.publishfee,
											upfee: that.data.upfee,
											upstate: that.data.upstate,
											res_id: res.data.res_id
										},
										success: function (sres) {
											wx.requestPayment({
												'timeStamp': sres.data.timeStamp,
												'nonceStr': sres.data.nonceStr,
												'package': sres.data.package,
												'signType': 'MD5',
												'paySign': sres.data.paySign,
												'success': function (pres) {
													getApp().util.request({
														url: 'entry/wxapp/Marketsuccess',
														data: {
															openid: wx.getStorageSync('openid'),
															res_id: res.data.res_id,
															upstate: that.data.upstate,
															alltype: 6
														},
														success: function (stres) {
															if (stres.data.code == 200) {
																wx.showToast({
																	title: '发布成功,等待审核...',
																	icon: 'none',
																	duration: 3000
																})
																setTimeout(function () {
																	wx.navigateBack({
																	})
																}, 1000)
															}
														}
													})
												},
												'fail': function (pres) {
													;
													wx.showToast({
														title: '支付失败',
														icon: "loading",
														duration: 1000
													})
												}
											})
										}
									})
								}else{
									getApp().util.request({
										url: 'entry/wxapp/Marketsuccess',
										data: {
											openid: wx.getStorageSync('openid'),
											res_id: res.data.res_id,
											upstate: that.data.upstate,
											alltype: 6
										},
										success: function (stres) {
											if (stres.data.code == 200) {
												wx.showToast({
													title: '发布成功,等待审核...',
													icon: 'none',
													duration: 3000
												})
												setTimeout(function () {
													wx.navigateBack({
													})
												}, 1000)
											}
										}
									})
								}
							}
						} else if (that.data.upstate != 1 && that.data.rest == 0 && that.data.restup > 0) {//9、11
							if (that.data.publishfee > 0) {//1(01)10
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 11
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1(01)00
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 9
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						} else if (that.data.upstate == 1 && that.data.rest == 0 && that.data.restup > 0) {//10、12
							if (that.data.publishfee > 0) {//1(01)11
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id,
										alltype:12
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 12
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1(01)01
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 10
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						} else if (that.data.upstate != 1 && that.data.rest > 0 && that.data.restup == 0) {//13、15
							if (that.data.publishfee > 0) {//1(10)10
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 15
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							} else {//1(10)00
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 13
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						} else if (that.data.upstate == 1 && that.data.rest > 0 && that.data.restup == 0) {//14、16
							if (that.data.publishfee > 0) {//1(10)11
								if(that.data.upfee>0){
									getApp().util.request({
										'url': 'entry/wxapp/Marketpay',
										'cachetime': '0',
										data: {
											openid: wx.getStorageSync('openid'),
											publishfee: that.data.publishfee,
											upfee: that.data.upfee,
											upstate: that.data.upstate,
											res_id: res.data.res_id,
											alltype: 16
										},
										success: function (sres) {
											wx.requestPayment({
												'timeStamp': sres.data.timeStamp,
												'nonceStr': sres.data.nonceStr,
												'package': sres.data.package,
												'signType': 'MD5',
												'paySign': sres.data.paySign,
												'success': function (pres) {
													getApp().util.request({
														url: 'entry/wxapp/Marketsuccess',
														data: {
															openid: wx.getStorageSync('openid'),
															res_id: res.data.res_id,
															upstate: that.data.upstate,
															alltype: 16
														},
														success: function (stres) {
															if (stres.data.code == 200) {
																wx.showToast({
																	title: '发布成功,等待审核...',
																	icon: 'none',
																	duration: 3000
																})
																setTimeout(function () {
																	wx.navigateBack({
																	})
																}, 1000)
															}
														}
													})
												},
												'fail': function (pres) {
													;
													wx.showToast({
														title: '支付失败',
														icon: "loading",
														duration: 1000
													})
												}
											})
										}
									})
								}else{
									getApp().util.request({
										url: 'entry/wxapp/Marketsuccess',
										data: {
											openid: wx.getStorageSync('openid'),
											res_id: res.data.res_id,
											upstate: that.data.upstate,
											alltype: 16
										},
										success: function (stres) {
											if (stres.data.code == 200) {
												wx.showToast({
													title: '发布成功,等待审核...',
													icon: 'none',
													duration: 3000
												})
												setTimeout(function () {
													wx.navigateBack({
													})
												}, 1000)
											}
										}
									})
								}
							} else {//1(10)01
								if(that.data.upfee){
									getApp().util.request({
										'url': 'entry/wxapp/Marketpay',
										'cachetime': '0',
										data: {
											openid: wx.getStorageSync('openid'),
											publishfee: that.data.publishfee,
											upfee: that.data.upfee,
											upstate: that.data.upstate,
											res_id: res.data.res_id
										},
										success: function (sres) {
											wx.requestPayment({
												'timeStamp': sres.data.timeStamp,
												'nonceStr': sres.data.nonceStr,
												'package': sres.data.package,
												'signType': 'MD5',
												'paySign': sres.data.paySign,
												'success': function (pres) {
													getApp().util.request({
														url: 'entry/wxapp/Marketsuccess',
														data: {
															openid: wx.getStorageSync('openid'),
															res_id: res.data.res_id,
															upstate: that.data.upstate,
															alltype: 14
														},
														success: function (stres) {
															if (stres.data.code == 200) {
																wx.showToast({
																	title: '发布成功,等待审核...',
																	icon: 'none',
																	duration: 3000
																})
																setTimeout(function () {
																	wx.navigateBack({
																	})
																}, 1000)
															}
														}
													})
												},
												'fail': function (pres) {
													;
													wx.showToast({
														title: '支付失败',
														icon: "loading",
														duration: 1000
													})
												}
											})
										}
									})
								}else{
									getApp().util.request({
										url: 'entry/wxapp/Marketsuccess',
										data: {
											openid: wx.getStorageSync('openid'),
											res_id: res.data.res_id,
											upstate: that.data.upstate,
											alltype: 14
										},
										success: function (stres) {
											if (stres.data.code == 200) {
												wx.showToast({
													title: '发布成功,等待审核...',
													icon: 'none',
													duration: 3000
												})
												setTimeout(function () {
													wx.navigateBack({
													})
												}, 1000)
											}
										}
									})
								}
							}
						} else if (that.data.upstate != 1 && that.data.rest > 0 && that.data.restup > 0) {//17、19
							if (that.data.publishfee > 0) {//1(11)10
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 19
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							} else {//1(11)00
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 17
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						} else if (that.data.upstate == 1 && that.data.rest > 0 && that.data.restup > 0) {//18、20
							if (that.data.publishfee > 0) {//1(11)11
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 20
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							} else {//1(11)01
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype: 18
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						}
					}else{
						if (that.data.upstate == 1){//2、4
							if (that.data.publishfee > 0) {//1011
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 4
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1001
								if(that.data.upfee>0){
									getApp().util.request({
										'url': 'entry/wxapp/Marketpay',
										'cachetime': '0',
										data: {
											openid: wx.getStorageSync('openid'),
											publishfee: that.data.publishfee,
											upfee: that.data.upfee,
											upstate: that.data.upstate,
											res_id: res.data.res_id
										},
										success: function (sres) {
											wx.requestPayment({
												'timeStamp': sres.data.timeStamp,
												'nonceStr': sres.data.nonceStr,
												'package': sres.data.package,
												'signType': 'MD5',
												'paySign': sres.data.paySign,
												'success': function (pres) {
													getApp().util.request({
														url: 'entry/wxapp/Marketsuccess',
														data: {
															openid: wx.getStorageSync('openid'),
															res_id: res.data.res_id,
															upstate: that.data.upstate,
															alltype:2
														},
														success: function (stres) {
															if (stres.data.code == 200) {
																wx.showToast({
																	title: '发布成功,等待审核...',
																	icon: 'none',
																	duration: 3000
																})
																setTimeout(function () {
																	wx.navigateBack({
																	})
																}, 1000)
															}
														}
													})
												},
												'fail': function (pres) {
													;
													wx.showToast({
														title: '支付失败',
														icon: "loading",
														duration: 1000
													})
												}
											})
										}
									})
								}else{
									getApp().util.request({
										url: 'entry/wxapp/Marketsuccess',
										data: {
											openid: wx.getStorageSync('openid'),
											res_id: res.data.res_id,
											upstate: that.data.upstate,
											alltype: 2
										},
										success: function (stres) {
											if (stres.data.code == 200) {
												wx.showToast({
													title: '发布成功,等待审核...',
													icon: 'none',
													duration: 3000
												})
												setTimeout(function () {
													wx.navigateBack({
													})
												}, 1000)
											}
										}
									})
								}
							}
						} else if(that.data.upstate != 1){//1、3
							if (that.data.publishfee > 0) {//1010
								getApp().util.request({
									'url': 'entry/wxapp/Marketpay',
									'cachetime': '0',
									data: {
										openid: wx.getStorageSync('openid'),
										publishfee: that.data.publishfee,
										upfee: that.data.upfee,
										upstate: that.data.upstate,
										res_id: res.data.res_id
									},
									success: function (sres) {
										wx.requestPayment({
											'timeStamp': sres.data.timeStamp,
											'nonceStr': sres.data.nonceStr,
											'package': sres.data.package,
											'signType': 'MD5',
											'paySign': sres.data.paySign,
											'success': function (pres) {
												getApp().util.request({
													url: 'entry/wxapp/Marketsuccess',
													data: {
														openid: wx.getStorageSync('openid'),
														res_id: res.data.res_id,
														upstate: that.data.upstate,
														alltype: 3
													},
													success: function (stres) {
														if (stres.data.code == 200) {
															wx.showToast({
																title: '发布成功,等待审核...',
																icon: 'none',
																duration: 3000
															})
															setTimeout(function () {
																wx.navigateBack({
																})
															}, 1000)
														}
													}
												})
											},
											'fail': function (pres) {
												;
												wx.showToast({
													title: '支付失败',
													icon: "loading",
													duration: 1000
												})
											}
										})
									}
								})
							} else {//1000
								getApp().util.request({
									url: 'entry/wxapp/Marketsuccess',
									data: {
										openid: wx.getStorageSync('openid'),
										res_id: res.data.res_id,
										upstate: that.data.upstate,
										alltype:1
									},
									success: function (stres) {
										if (stres.data.code == 200) {
											wx.showToast({
												title: '发布成功,等待审核...',
												icon: 'none',
												duration: 3000
											})
											setTimeout(function () {
												wx.navigateBack({
												})
											}, 1000)
										}
									}
								})
							}
						}
					}
				}
			}
		})
	}
})